import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { Document, Schema as MongooseSchema } from 'mongoose';
import { ApiProperty } from '@nestjs/swagger';

export type RoleDocument = Role & Document;

@Schema({ timestamps: true })
export class Role {
  @ApiProperty({ description: '角色名称', example: '管理员' })
  @Prop({ required: true })
  name: string;

  @ApiProperty({ description: '角色编码', example: 'ADMIN' })
  @Prop({ unique: true })
  code: string;

  @ApiProperty({ description: '角色描述' })
  @Prop()
  description: string;

  @ApiProperty({ description: '所属组织ID' })
  @Prop({ type: MongooseSchema.Types.ObjectId, ref: 'Organization' })
  orgId: MongooseSchema.Types.ObjectId;

  @ApiProperty({ description: '权限ID列表', type: Array })
  @Prop({ type: [{ type: MongooseSchema.Types.ObjectId, ref: 'Permission' }] })
  permissionIds: MongooseSchema.Types.ObjectId[];

  @Prop()
  remark: string;

  @Prop({ default: 1 }) // 0: 禁用, 1: 启用
  status: number;
}

export const RoleSchema = SchemaFactory.createForClass(Role); 